import torch
import torch.nn.functional as F


class ResBlock(torch.nn.Module):
    def __init__(self, channels):
        super(ResBlock, self).__init__()
        self.channels = channels
        self.conv1 = torch.nn.Conv2d(channels, channels, kernel_size = 3, padding = 1)
        self.conv2 = torch.nn.Conv2d(channels, channels, kernel_size = 3, padding = 1)

    def forward(self, x):
        y = F.relu(self.conv1(x))
        y = self.conv2(y)
        return F.relu(x + y)


class Model(torch.nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.conv1 = torch.nn.Conv2d(1, 16, kernel_size = 5)
        self.conv2 = torch.nn.Conv2d(16, 32, kernel_size = 5)
        self.pool = torch.nn.MaxPool2d(2)
        self.l1 = torch.nn.Linear(512, 256)
        self.l2 = torch.nn.Linear(256, 128)
        self.l3 = torch.nn.Linear(128, 64)
        self.l4 = torch.nn.Linear(64, 10)
        self.l5 = torch.nn.Linear(128, 64)
        self.l6 = torch.nn.Linear(64, 10)
        self.resblock1 = ResBlock(16)
        self.resblock2 = ResBlock(32)

    def forward(self, x):
        in_size = x.size(0)
        x = self.pool(F.relu(self.conv1(x)))
        x = self.resblock1(x)
        x = self.pool(F.relu(self.conv2(x)))
        x = self.resblock2(x)

        return x


if __name__ == '__main__':
    batch_size = 64
    in_channels = 1
    width, height = 28, 28
    input = torch.randn(batch_size, in_channels, width, height)
    model = Model()
    output = model(input)
    print(output.shape)
